<?php

namespace App\Remote\OceanEngine;

use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Validation\ValidationException;
use Symfony\Component\HttpFoundation\Request as RequestAlias;

class AuthRemote extends Remote
{

    /**
     * 获取token
     *
     * @param string $code
     * @return mixed
     * @throws GuzzleException
     * @throws ValidationException
     */
    public static function authToken(string $code)
    {
        return self::customRequestV3(
            "/open_api/oauth2/access_token/",
            RequestAlias::METHOD_POST,
            [
                "app_id"    => "1791927674355851",
                "secret"    => "b2d1cdf299e4e4e30b5626d8b956ad12603d329a",
                "auth_code" => $code
            ]
        );
    }

    /**
     * 刷新token
     *
     * @param string $refreshToken
     * @return mixed
     * @throws GuzzleException
     * @throws ValidationException
     */
    public static function refreshToken(string $refreshToken)
    {
        return self::customRequestV3(
            "/open_api/oauth2/refresh_token/",
            RequestAlias::METHOD_POST,
            [
                "app_id"        => "1791927674355851",
                "secret"        => "b2d1cdf299e4e4e30b5626d8b956ad12603d329a",
                "refresh_token" => $refreshToken
            ]
        );
    }

}
